package com.digua.base.socket.response

import com.digua.base.socket.dispatcher.IResponseDispatcher
import com.digua.base.socket.dispatcher.ResponseDelivery
import java.nio.ByteBuffer


class ByteBufferResponse : Response<ByteBuffer> {
    private var data: ByteBuffer? = null

    override fun getResponseData(): ByteBuffer? {
        return data
    }

    override fun setResponseData(responseData: ByteBuffer) {
        data = responseData
    }

    override fun onResponse(dispatcher: IResponseDispatcher?, delivery: ResponseDelivery?) {
        data?.let { dispatcher?.onMessage(it, delivery) }
        release()
    }

    override fun toString() = "[@ByteBufferResponse${hashCode()}->ByteBuffer:${data ?: "null"}]"

    override fun release() {
        ResponseFactory.releaseByteBufferResponse(this)
    }
}